SQL SERVER 查询列名、表/列是否存在

您所在的位置:网站首页 sql 查询列名 SQL SERVER 查询列名、表/列是否存在

SQL SERVER 查询列名、表/列是否存在

2023-07-15 11:47| 来源: 网络整理| 查看: 265

1、sqlserver获取表的所有列: select name from syscolumns Where id=object_Id('NIS_HLZK_JCBD');

2、判断表格是否存在: select 1 from sysobjects where id=object_id('NIS_HLZK_ZKJH_MX_JC') and type = 'U'

3、判断表格的列是否存在: select 1 from syscolumns where name='JSFS' and id=object_id('NIS_HLZK_ZKJH_MX_JC')

4、获取表或视图的所有字段及数据类型、长度:

select a.name tablename, b.name colName, c.name colType ,c.length colLength from sysobjects a inner join syscolumns b on a.id=b.id and a.xtype in ('U','V') inner join systypes c on b.xtype=c.xusertype where a.name='表名'

参照网址:https://blog.csdn.net/99guo/article/details/40142599

5、查询视图的所有列及列类型:

sp_help 'VIEW_HLZK_KSZHCXFX ' Select c.name As ColumnsName , t.name As ColumnsType From sysobjects As o , syscolumns As c , systypes As t Where o.type in ('u','v') And o.id = c.id And c.xtype = t.xtype And o.name = 'VIEW_HLZK_KSZHCXFX'

后台获取采用4中的sql进行查询。

参照网址:https://blog.csdn.net/u012965373/article/details/52791374



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3